# Maintainer: David Runge <dvzrv@archlinux.org>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Sirat18 <aur@sirat18.de>
# Contributor: Jonas Heinrich <onny@project-insanity.org>

pkgname=python-icalendar
_name=${pkgname#python-}
pkgver=5.0.11
pkgrel=1
pkgdesc='A parser/generator of iCalendar files (RFC 2445)'
arch=(any)
url="https://github.com/collective/icalendar"
license=(BSD)
depends=(python-dateutil python-pytz)
makedepends=(git python-build python-installer python-setuptools python-wheel)
checkdepends=(python-hypothesis python-pytest)
source=("git+$url.git#tag=v$pkgver")
b2sums=('SKIP')

build() {
  cd "$_name"
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "$_name"
  pytest -v "src/$_name/tests"
}

package() {
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd "$_name"
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 {CHANGES,CONTRIBUTING,README}.rst -t "$pkgdir/usr/share/doc/$pkgname/"

  install -d "$pkgdir/usr/share/licenses/$pkgname/"
  ln -s "$site_packages/$_name-$pkgver.dist-info/LICENSE.rst" "$pkgdir/usr/share/licenses/$pkgname/LICENSE.rst"

  rm -frv "$pkgdir/$site_packages/$_name/tests/"
}
